public class PrimeNumbers {  

    public static boolean isPrime(int num) {  
        if (num <= 1) {  
            return false;  
        }  
        for (int i = 2; i <= Math.sqrt(num); i++) {  
            if (num % i == 0) {  
                return false;  
            }  
        }  
        return true;  
    }  
  
    public static void main(String[] args) {  
        int count = 0;  
        for (int i = 1; i <= 20000; i++) {  
            if (isPrime(i)) {  
                System.out.print(i + " ");  
                count++;  
                if (count % 5 == 0) {  
                    System.out.println(); 
                }  
            }  
        }  
    }  
}